<%--
@Created by IntelliJ IDEA
@Project_Name ieco_server
@Package 
@Author ZhongYao_H
@Date 2019/5/14:10:02
@Year 2019 Month 05 Day 14
@Date_zh  2019年 五月 星期二
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico"> <link href="${pageContext.request.contextPath}/assets/hplus/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
<%--    <%@include file="/WEB-INF/common/ueditor.jsp"%>--%>
<%--    <link href="${pageContext.request.contextPath}/assets/hplus/css/font-awesome.css?v=4.4.0" rel="stylesheet">--%>
    <link href="${pageContext.request.contextPath}/assets/hplus/css/animate.css" rel="stylesheet">
<%--    <link href="${pageContext.request.contextPath}/assets/hplus/css/plugins/summernote/summernote.css" rel="stylesheet">--%>
<%--    <link href="${pageContext.request.contextPath}/assets/hplus/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">--%>
    <link href="${pageContext.request.contextPath}/assets/hplus/css/style.css?v=4.1.0" rel="stylesheet">
    <style>

        html,body{
            height: 100%;
            width: 100%;
        }

    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content">

    <form  class="form-horizontal m-t" action="${pageContext.request.contextPath}/article/add" id="form" method="post">
        <div class="form-group">
            <label class="col-sm-3 control-label">文章类型：</label>
            <div class="col-sm-2">
                <select name="type" class="col-sm-6 form-control" >
                <option value="1">产品</option>
                <option value="4">其他</option>
                <option value="2">分类攻略</option>
                <option value="3">首页轮播</option>
                </select>
            </div>
            <label class="col-sm-1 control-label">标题：</label>
            <div class="col-sm-4">
                <input type="text"  name="title" id="title" class="form-control"
                       placeholder="">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">简要描述：</label>
            <div class="col-sm-7">
                <input type="text"  name="anno" class="form-control" maxlength="35"
                       placeholder="">
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label"><span id="required">*</span>封面图片：</label>
            <div class="col-sm-2">
                <input type="button" onclick="fileclick()" value="上传" class="form-control" aria-required="true"
                required="required" />
                <input type="hidden" aria-required="true"
                       required="required" name="coverId" id="cover"  >
            </div>
            <label class="col-sm-1 control-label"><span></span></label>
            <div class="col-sm-2">
                <img   class="image"  style="width: 190px;height: 110px;display: none" src="" id="img" >
            </div>
        </div>

        <input type="hidden" name="body" id="body">

    </form>
    <div class="row" style="height: 50%;width: 100%;padding: 30px">
                <div class="ibox-content" style="width: 100%" id="eg">

                </div>
    </div>

    <div class="form-group">
        <div class="col-sm-4 col-sm-offset-3" style="text-align: center;">
            <button class="btn btn-primary" id="add-btn" onclick="submit()" type="button">提交</button>
            <button class="btn btn-danger" onclick="javascript :history.go(-1);" type="button">返回</button>
        </div>
    </div>

</div>


 <div id="hiden" style="display: none">
 <form id="fileform" action="${pageContext.request.contextPath}/file/uploadimage" enctype="multipart/form-data">
     <input name="file" id="file" accept="image/jpeg,image/jpg,image/png,image/gif" onchange="imgUpload(this)" type="file">
 </form>
 </div>

<!-- 加载编辑器的容器 -->
<script id="eg" name="eg" type="text/plain">
        这里写你的初始化内容
</script>
<script src="${pageContext.request.contextPath}/assets/js/plugins/ueditor1.4.3.3/ueditor.config.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/plugins/ueditor1.4.3.3/ueditor.all.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/plugins/ueditor1.4.3.3/lang/zh-cn/zh-cn.js"></script>

<!-- 全局js -->
<%--<script src="${pageContext.request.contextPath}/assets/hplus/js/jquery.min.js?v=2.1.4"></script>--%>
<script src="${pageContext.request.contextPath}/assets/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/hplus/js/bootstrap.min.js?v=3.3.6"></script>
<!-- 自定义js -->
<script src="${pageContext.request.contextPath}/assets/hplus/js/content.js?v=1.0.0"></script>

<!-- SUMMERNOTE -->
<%--<script src="${pageContext.request.contextPath}/assets/hplus/js/plugins/summernote/summernote.min.js"></script>--%>
<%--<script src="${pageContext.request.contextPath}/assets/hplus/js/plugins/summernote/summernote-zh-CN.js"></script>--%>
<script type="text/javascript">

    $(document).ready(function () {

    });
    var ue = UE.getEditor('eg');

    var ue = UE.getEditor('eg', {
        autoHeight: false
    });

    //对编辑器的操作最好在编辑器ready之后再做
    ue.ready(function() {
        //设置编辑器的内容
        ue.setContent('');
        console.log("编辑器初始化完成");
        //获取html内容，返回: <p>hello</p>
        var html = ue.getContent();
        //获取纯文本内容，返回: hello
        var txt = ue.getContentTxt();
    });

    function getContenTxt() {
        var html  = ue.getContent();
        console.log(html);
        $("#body").val(html);
    }


     function submit() {
         getContenTxt();

         var title = $("#title").val();
         if (title==''){
             alert("标题不能为空!");
             return
         }

         var  cover = $("#cover").val();
         if (cover==''){
             alert("没有上传封面");
             return;
         }


        $("#form").ajaxSubmit({
            dataType:'json',
            type:"POST",
            success:function (josn) {
                var code = josn.code;
                if (code==0){
                    alert("发布成功!");
                    window.location.reload();
                }else {
                    alert("系统异常稍后重试!");
                }
            }
        });
    }


     function fileclick() {
        $('#file').click();
    }

     function imgUpload(obj) {
         var file = obj.files[0];
         console.log(obj);console.log(file);
         console.log("file.size = " + file.size);  //file.size 单位为byte

         var reader = new FileReader();

         //读取文件过程方法
         reader.onloadstart = function (e) {
             console.log("开始读取....");
         }
         reader.onprogress = function (e) {
             console.log("正在读取中....");
         }
         reader.onabort = function (e) {
             console.log("中断读取....");
         }
         reader.onerror = function (e) {
             console.log("读取异常....");
         }
         reader.onload = function (e) {
             console.log("成功读取....");

             var img = document.getElementById("img");
             $("#img").show();
             img.src = e.target.result;
             //或者 img.src = this.result;  //e.target == this
         }

         reader.readAsDataURL(file)


         console.log("上传图片");
        $("#fileform").ajaxSubmit({
            type:'POST',
            dataType:'json',
            success:function (json) {
                var code = json.code;
                var id = json.id;
                if (code ==0){
                    $("#cover").val(id);

                }else {

                }

            }


        });
    }
</script>
<script type="text/javascript">


</script>
<%--<script>--%>
<%--    $(document).ready(function () {--%>

<%--        $('.summernote').summernote({--%>
<%--            lang: 'zh-CN'--%>
<%--        });--%>





<%--    });--%>



<%--    var edit = function () {--%>

<%--        $("#main").empty();--%>
<%--        $("#eg").addClass("no-padding");--%>
<%--        $('.click2edit').summernote({--%>
<%--            lang: 'zh-CN',--%>
<%--            focus: true--%>
<%--        });--%>
<%--    };--%>
<%--    var save = function () {--%>
<%--        $("#eg").removeClass("no-padding");--%>
<%--        var allHTML = $('.click2edit').code(); // 这是编辑好的源码 图片以base64编码存储--%>
<%--        console.log(allHTML)--%>
<%--        $("#body").val(allHTML)--%>

<%--        $('.click2edit').destroy();--%>
<%--    };--%>



<%--</script>--%>

<%--<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>--%>
</body>
</html>
